**********************************************************************************************
* Reproduces Figures A.5
*
* Cloyne, Dimsdale and Hürtgen (2024) 								
*	"Are Tax Cuts Contractionary at the Zero Lower Bound? Evidence from a Century of Data"  	  		
*																			
* James Cloyne, Nicholas Dimsdale and Patrick Hürtgen, 2024
**********************************************************************************************


global outputfolder = "${rootfolder}/StateDep"
capture mkdir ${outputfolder}
global outputfolder = "${outputfolder}/${figure}"
capture mkdir ${outputfolder}

* control set specification
capture macro drop controlist 
capture macro drop controlist1 controlist2


*---------------------------------------------------------*
*-------------------- Setup --------------------*
*---------------------------------------------------------*

global approach = "LP"
global LHS = "smoothed"

* Sample harmonization
global harmonized = 0


* ---------- LP regression --------------- *
global qLags = 4  // lags for Tax shocks
global pLags = 4  // lags for controls
global gLags = 0  // lags for government spending shock controls
global hmax = ${hmax}

global controlist lnRealGDP lnRealTaxRev lnRealExp BankRate 		

/* -------------  Baseline LP ------------ */

use ${datapath}/${DataSetName},clear

forv pair = 1/5 {
	
	if `pair' == 1 {
		global ForceZLB = 0
	}
	else if `pair' == 2 {
		global ForceZLB = 2
	}
	else if `pair' == 3 {
		global ForceZLB = 6
	}
	else if `pair' == 4 {
		global ForceZLB = 8
	}
	else if `pair' == 5 {
		global ForceZLB = 4
	}
	
	
	do ${dofilepath}/MacroData_${shockversion}Shocks.do
		

foreach y in lnRealGDP {
	
	preserve 
	global depvar = "`y'"

	do ${dofilepath}/LP_DataTransform_LR.do

	local labely : variable label $depvar
	local yname = subinstr("`labely'"," ","",.)
	local filename = "S_`yname'ToTax_${LHS}" 

	if $skipsample == 1 {
		local filename = "`filename'_s"  
	}
	
	log close _all 

	log using ${outputfolder}/`filename', name(StateDep_ZLB_${depvar}) text replace

	do ${dofilepath}/LP_IRFs_StateDep.do
	
	if $PlotIRF == 1 & $saveFigs == 1 {

		forv j = 0/1 {
			gr export "${outputfolder}/IRF_`filename'_Regime`j'_Pair`pair'.pdf", name(IRF_`yname'_`j') replace
			
		}
	}
	
	keep Quarters b0 b1 u${alpha2}* d${alpha2}* u${alpha1}* d${alpha1}*
	drop if Quarters == .
	
	ren b0 point_NoZLB
	ren b1 point_ZLB
	ren u${alpha2}0 u${alpha2}_NoZLB
	ren u${alpha2}1 u${alpha2}_ZLB
	ren u${alpha1}0 u${alpha1}_NoZLB
	ren u${alpha1}1 u${alpha1}_ZLB
	ren d${alpha2}0 d${alpha2}_NoZLB
	ren d${alpha2}1 d${alpha2}_ZLB
	ren d${alpha1}0 d${alpha1}_NoZLB
	ren d${alpha1}1 d${alpha1}_ZLB
	
	save "${outputfolder}/DataIRF_`filename'_`y'_${LHS}_Pair`pair'.dta", replace
	export excel "${outputfolder}/DataIRF_`filename'_`y'_${LHS}_Pair`pair'.xlsx", firstrow(variables)  keepcellfmt replace

	log close _all
	restore
}



}




